#!/bin/awk -f
## select tiling number from tilings.out
BEGIN{
#  sel=ARGV[1]; ARGV[1]="-"; ARGC=2;
}
FNR==1{
  nn=$1; mu=$2; nt=$3;
#  nt=500;
  print nn,mu,nt;
}
FNR>1&&FNR<4{print} #basis
FNR==3{
#  print nn,mu;
  printf "tilesort: ">"/dev/stderr";
  nnl=nn/mu;
  for(i=1;i<=nt;i++){ # tilings
    printf "." > "/dev/stderr";    
    for(k=1;k<=mu;k++){ # layers
      s="";
#      print "layer "k;
      for(j=1;j<=nnl;j++){ # nodes
	getline;
	for(l=1;l<=5;l++){s=s""$l;if(l<5){s=s" "}else{s=s"  "nu"\n"}}
      };
#      printf s;
      mypipe="sort -n";
      printf s | mypipe;
      close(mypipe);
    }
  }
}
END{
  printf " done";
}
